package data;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;


public class Vocabulary
{
	private List<String> words;
	private HashMap<String, Integer> indexes;
	
	
	public Vocabulary(Collection<WordOccurrenceMap> wordOccurrenceMaps)
	{
		HashSet<String> wordSet = new HashSet<>();
		for (WordOccurrenceMap wordOccurrenceMap : wordOccurrenceMaps)
		{
			wordSet.addAll(wordOccurrenceMap.keySet());
		}
		words = new ArrayList<String>(wordSet);
		creatIndexes();
	}
	
	public Vocabulary(List<String> words)
	{
		this.words = words;
		creatIndexes();
	}
	
	private void creatIndexes()
	{
		indexes = new HashMap<>();
		for (int i = 0; i < words.size(); i++)
		{
			indexes.put(words.get(i), i);
		}
	}

	public List<String> getWords()
	{
		return words;
	}

	public Map<String, Integer> getIndexes()
	{
		return indexes;
	}
}
